//
//  LNHGoodsDetailSelectView.m
//  LNH
//
//  Created by cruise on 2018/2/7.
//  Copyright © 2018年 twentylx. All rights reserved.
//

#import "LNHGoodsDetailSelectView.h"

@interface LNHGoodsDetailSelectView()

@property (nonatomic, strong) UIView *bgButtonView1;
@property (nonatomic, strong) UILabel *leftLabel1;
@property (nonatomic, strong) UIImageView *rightImageView1;

@property (nonatomic, strong) UIView *bgButtonView2;
@property (nonatomic, strong) UILabel *leftLabel2;
@property (nonatomic, strong) UIImageView *rightImageView2;

@property (nonatomic, strong) UIView *lineView;

@end

@implementation LNHGoodsDetailSelectView

/**
 为视图绑定 viewModel
 
 @param viewModel 要绑定的ViewModel
 @param params 额外参数
 */
- (void)bindViewModel:(id <LMViewProtocol>)viewModel withParams:(NSDictionary *)params{
    
}

/**
 初始化额外数据
 */
- (void)lm_initializeForView{
    
}

/**
 初始化视图
 */
- (void)lm_createViewForView{
    
    [self setBackgroundColor:[UIColor whiteColor]];
    
    [self addSubview:self.bgButtonView1];
    [self.bgButtonView1 addSubview:self.leftLabel1];
    [self.bgButtonView1 addSubview:self.rightImageView1];
    
    [self addSubview:self.bgButtonView2];
    [self.bgButtonView1 addSubview:self.leftLabel2];
    [self.bgButtonView1 addSubview:self.rightImageView2];
    
    [self addSubview:self.lineView];
    
    [self setNeedsUpdateConstraints];
}

-(void) updateConstraints {
    
    [self.bgButtonView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.height.equalTo(self).dividedBy(2);
    }];
    
    [self.leftLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.bgButtonView1);
        make.left.equalTo(self.bgButtonView1).offset(20);
    }];
    
    [self.rightImageView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.bgButtonView1);
        make.right.equalTo(self.bgButtonView1.mas_right).offset(-15);
        make.size.mas_equalTo(CGSizeMake(8, 15));
    }];
    
    [self.bgButtonView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.bottom.equalTo(self.mas_bottom);
        make.height.equalTo(self).dividedBy(2);
    }];
    
    [self.leftLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.bgButtonView2);
        make.left.equalTo(self.bgButtonView2).offset(20);
    }];
    
    [self.rightImageView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.bgButtonView2);
        make.right.equalTo(self.bgButtonView2.mas_right).offset(-15);
        make.size.mas_equalTo(CGSizeMake(8, 15));
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(10);
        make.right.equalTo(self).offset(-10);
        make.centerY.equalTo(self);
        make.height.mas_equalTo(ONE_PIXEL);
    }];
    
    [super updateConstraints];
    
}

#pragma mark - Getter

-(UIView *) bgButtonView1 {
    if (!_bgButtonView1) {
        _bgButtonView1 = [UIView new];
        [_bgButtonView1 setUserInteractionEnabled:YES];
        @weakify(self);
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
        [[tap rac_gestureSignal] subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
            @strongify(self);
            if (self.delegate && [self.delegate respondsToSelector:@selector(popSelectSizeView)]) {
                [self.delegate popSelectSizeView];
            }
            
        }];
        [_bgButtonView1 addGestureRecognizer:tap];
    }
    return _bgButtonView1;
}

-(UILabel *) leftLabel1 {
    if (!_leftLabel1) {
        _leftLabel1 = [UILabel new];
        [_leftLabel1 setTextColor:RGBCOLOR(90, 90, 90)];
        [_leftLabel1 setFont:[UIFont systemFontOfSize:14]];
        [_leftLabel1 setText:@"选择尺码"];
    }
    return _leftLabel1;
}

-(UIImageView *) rightImageView1 {
    if (!_rightImageView1) {
        _rightImageView1 = [UIImageView new];
        [_rightImageView1 setImage:LMImageNamed(@"right_arrow_img")];
        _rightImageView1.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _rightImageView1;
}

-(UIView *) bgButtonView2 {
    if (!_bgButtonView2) {
        _bgButtonView2 = [UIView new];
        @weakify(self);
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
        [[tap rac_gestureSignal] subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
            @strongify(self);
            if (self.delegate && [self.delegate respondsToSelector:@selector(popGoodsInfoView)]) {
                [self.delegate popGoodsInfoView];
            }
            
        }];
        [_bgButtonView2 addGestureRecognizer:tap];
    }
    return _bgButtonView2;
}

-(UILabel *) leftLabel2 {
    if (!_leftLabel2) {
        _leftLabel2 = [UILabel new];
        [_leftLabel2 setTextColor:RGBCOLOR(90, 90, 90)];
        [_leftLabel2 setFont:[UIFont systemFontOfSize:14]];
        [_leftLabel2 setText:@"产品参数"];
    }
    return _leftLabel2;
}

-(UIImageView *) rightImageView2 {
    if (!_rightImageView2) {
        _rightImageView2 = [UIImageView new];
        [_rightImageView2 setImage:LMImageNamed(@"right_arrow_img")];
        _rightImageView2.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _rightImageView2;
}

-(UIView *) lineView {
    if (!_lineView) {
        _lineView = [UIView new];
        [_lineView setBackgroundColor:RGBCOLOR(217, 217, 217)];
    }
    return _lineView;
}

@end
